import React from 'react'
import {connect} from 'react-redux'
import { HashRouter as Router,Route,Switch,Redirect} from 'react-router-dom'

import Main from './layout/main/index'
import Login from './layout/login/index'

const App=({loginState})=>{
  
    return (
        <Router >
          <Switch>
            {/* <Route path="/login" component = { Login } /> */}
            {
              loginState ?
              <Redirect path="/login" to="/" /> :
              <Route path="/login" component = { Login } />
            }
            {/* <Route path="/" component = { Main } /> */}
            {
              // 前端验证用户的登录状态
              loginState ?
              <Route path="/" component = { Main } /> :
              <Redirect to="/login" />
              

            }
          </Switch>
        </Router>
      )
}

const mapState=(state)=>{
    return {
        loginState:state.getIn(['admin','loginState'])
    }
}
export default connect(mapState)(App)